package user

import (
	"data/config"
	"public/mysqldb"
)

//通过手机号获取用户名
func OnGetUserNameFromPhone(phone string) string {
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())
	var tmp Cell_bind_tbl
	orm.Where("phone = ?", phone).Find(&tmp)
	return tmp.Username
}

//通过用户名获取手机号
func OnGetPhoneFromUserName(username string) string {
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())
	var tmp Cell_bind_tbl
	orm.Where("username = ?", username).Find(&tmp)
	return tmp.Phone
}

//绑定手机号
func OnBindPhone(username, phone string) bool {
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())
	var tmp Cell_bind_tbl
	tmp.Phone = phone
	tmp.Username = username
	return orm.Save(&tmp).Error == nil
}
